//
//  BusinessService.m
//  HappyStore
//
//  Created by 点点充 on 16/1/20.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "BusinessService.h"

@interface BusinessService ()<UICollectionViewDelegate>
{
    NSArray *aryImgName;
    NSString *strType;
}
@end

@implementation BusinessService

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16.f],NSFontAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"企业服务";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    
    aryImgName = @[@"软件开发",@"融资担保",@"上市辅导",
                   @"法律咨询",@"财务会计",@"商标专利",
                   @"展会会务",@"广告传媒",@"工商注册",
                   @"营销策划",@"aa",@"aa"];
    
    //取消返回的文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    // 设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.view.backgroundColor = [UIColor whiteColor];
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 64, screenW, 2)];
    backView.backgroundColor = RGB(247, 247, 247);
    [self.view addSubview:backView];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

- (void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark- UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 12;
    
}
//行内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *collectionViewCell = @"BusinessServiceCollectionViewCell";
    UICollectionViewCell *cell;
    
    
    cell= [collectionView dequeueReusableCellWithReuseIdentifier:collectionViewCell forIndexPath:indexPath];
//    cell.contentView.layer.borderColor = [UIColor colorWithWhite:0.5 alpha:0.7f].CGColor;
//    cell.contentView.layer.borderWidth = 0.5;
    
//    UILabel *labFGRight = [[UILabel alloc] initWithFrame:(CGRect){105.5,0,0.5,106}];
//    labFGRight.backgroundColor = [UIColor colorWithWhite:0.5f alpha:0.7f];
//    [cell.contentView addSubview:labFGRight];
//    
//    UILabel *labFGBottom = [[UILabel alloc] initWithFrame:(CGRect){0,105.5,106,0.5}];
//    labFGBottom.backgroundColor = [UIColor colorWithWhite:0.5f alpha:0.7f];
//    [cell.contentView addSubview:labFGBottom];
    
    
    UIButton *btn = [cell viewWithTag:10];
    [btn setImage:[UIImage imageNamed:aryImgName[indexPath.row]] forState:UIControlStateNormal];
    
    if (indexPath.row < aryImgName.count-2) {
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    
    return cell;
}

//点击效果
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //    NSLog(@"%ld",indexPath.row);
//    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
//    NSLog(@"%ld",indexPath.row);
//    UIButton *btn = (UIButton *)[cell viewWithTag:20 + indexPath.row];
}


- (void)btnClick:(UIButton *)sender
{
    NSInteger indexPath = 0;
    for (int i = 0; i<aryImgName.count; i++) {
        UIImage *image = [UIImage imageNamed:aryImgName[i]];
        if ([sender.currentImage isEqual:image]) {
            indexPath = i;
        }
    }
    
    //NSLog(@"----%ld",indexPath);
    //软件开发.融资担保.法律咨询.财务会计.商标专利.展会会务.广告传媒.工商注册.营销策划
    switch (indexPath) {
        case 0://SoftwareDevelop
        {
            strType = @"软件开发";
        }
            break;
        case 1:
        {
            strType = @"融资担保";
        }
            break;
        case 2:
        {
            strType = @"上市辅导";
        }
            break;
        case 3:
        {
            strType = @"法律咨询";
        }
            break;
        case 4:
        {
            strType = @"财务会计";
        }
            break;
        case 5:
        {
            strType = @"商标专利";
        }
            break;
        case 6:
        {
            strType = @"展会会务";
        }
            break;
        case 7:
        {
            strType = @"广告传媒";
        }
            break;
        case 8:
        {
            strType = @"工商注册";
        }
            break;
        case 9:
        {
            strType = @"营销策划";
        }
            break;
            
        default:
            break;
    }
    
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    [self performSegueWithIdentifier:@"softwareDevelop" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // segue.identifier：获取连线的ID
    if ([segue.identifier isEqualToString:@"softwareDevelop"]) {
        SoftwareDevelop *result = segue.destinationViewController;
        result.strType = strType;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
